"""MxsShop URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/3.1/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
from django.conf.urls.static import static
from django.contrib import admin
from django.urls import path, include, re_path
from MxsShop import settings
from apps.goods.views import GoodsListViewSet, CategoryViewSet, HotSearchViewSet, BannerViewSet, IndexCategoryViewSet
from rest_framework.routers import DefaultRouter
from rest_framework_jwt.views import obtain_jwt_token
from rest_framework.authtoken import views
from apps.users.views import SmsCodeViewSet, UserViewSet
from apps.user_operation.views import UserFavViewSet, LeavingMessageViewSet, AddressViewSet
from rest_framework.schemas import get_schema_view
from rest_framework_swagger.renderers import SwaggerUIRenderer, OpenAPIRenderer
from apps.trade.views import ShoppingCartViewSet, OrderViewSet

from drf_yasg import openapi
from drf_yasg.views import get_schema_view
from rest_framework import permissions, routers

schema_view = get_schema_view(openapi.Info(
    title="慕学接口API",
    default_version="v1",
    description="慕学接口API接口说明",
    terms_of_service="",
    contact=openapi.Contact(email="zmrenwu@163.com"),
    license=openapi.License(name="GPLv3 License"),
),
    public=True,
    permission_classes=(permissions.AllowAny,),
)

#  swagger
# schema_view = get_schema_view(title='慕学接口', renderer_classes=[OpenAPIRenderer, SwaggerUIRenderer])

router = DefaultRouter()

# 配置goods的url
router.register('goods', GoodsListViewSet, basename='goods')
# 配置category的url
router.register('categorys', CategoryViewSet, basename='categorys')
# 短信验证码
router.register('code', SmsCodeViewSet, basename='codes')
# 用户登录
router.register('users', UserViewSet, basename='users')
# 用户收藏
router.register('userfavs', UserFavViewSet, basename='userfavs')
# 热词搜索
router.register('hotsearchs', HotSearchViewSet, basename="hotsearchs")
# 留言
router.register('messages', LeavingMessageViewSet, basename='leave_message')
# 收货地址
router.register('address', AddressViewSet, basename='address')
# 购物车
router.register('shopcarts', ShoppingCartViewSet, basename='shopcarts')
# 订单
router.register('orders', OrderViewSet, basename='orders')
# 首页轮播图
router.register('banners', BannerViewSet, basename='banners')
# 首页商品系列数据
router.register('indexgoods', IndexCategoryViewSet, basename='indexgoods')

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include(router.urls)),
    path('api-auth/', include('rest_framework.urls', namespace='rest_framework')),
    # path('swagger/', schema_view, name='docs'),
    # DRF自带的token认证模式
    path('api-token-auth/', views.obtain_auth_token),
    # jwt的认证接口
    path('login/', obtain_jwt_token),
    re_path(r"swagger(?P<format>\.json|\.yaml)", schema_view.without_ui(cache_timeout=0), name="schema-json", ),
    path("swagger/", schema_view.with_ui("swagger", cache_timeout=0), name="schema-swagger-ui", ),
    path("redoc/", schema_view.with_ui("redoc", cache_timeout=0), name="schema-redoc"),
]

urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
